package com.ht.controller;

import com.ht.bean.Notice;
import com.ht.bean.Student;
import com.ht.service.NoticeService;
import com.ht.service.StudentLoginService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/studentLogin")
public class StudentLoginController {


    @Resource
    private StudentLoginService studentLoginService;

    @Resource
    private NoticeService noticeService;



    @RequestMapping("/goindex")
    public String gologin(String phone, String password, Model model, HttpSession session, Notice notice){

        Student student = studentLoginService.studentlogin(phone,password);
        if (student == null){//如果登录失败
            model.addAttribute("message","账号或密码错误，请重新输入！");
            return "forward:/system.jsp";
        } else  if (student.getStat() == 2){
            model.addAttribute("messages","该账号被禁用，请联系管理员");
            return "forward:/index.jsp";
        } else {//登录成功
            model.addAttribute("messages","登录成功");
            session.setAttribute("STU",student);
            session.setAttribute("STUID",student.getStuId());
            session.setAttribute("STUNAME",student.getStuname());
            return "redirect:/studentLogin/goFillin";
        }
    }

    @RequestMapping("/goFillin")
    public String gotest(){
        return "fillin";
    }

    @RequestMapping("/goexit")
    public String goexit(){
        return "forward:/system.jsp";
    }

    @RequestMapping("/gostuhome")
    public String gostuhome(){
        return "stuhome";
    }

}
